home *** CD-ROM | disk | FTP | other *** search
Wrap
package com.extensibility.exv; import com.extensibility.xml.BaseDeclaration; import com.extensibility.xml.BaseExemplar; import com.extensibility.xml.BaseFlavor; import com.extensibility.xml.ParserException; import com.extensibility.xml.Schema; import com.extensibility.xml.SchemaIntf; import com.extensibility.xml.SchemaUtilities; import com.extensibility.xml.SchemaWriter; import com.extensibility.xml.URI; import java.io.StringWriter; import java.util.Enumeration; import java.util.ResourceBundle; import java.util.Vector; public class ExtSchemaValidator { static final String NOT_WELL_FORMED_MESSAGE = "Schema is not well-formed."; static final String XML_RESOURCE_PKG = "com.extensibility.xml.rsc."; ResourceBundle ParserErrorBundle; ResourceBundle ErrorSituationBundle; ResourceBundle dataTypeDisplayNames; ResourceBundle XMLResources; boolean isSchemaValid = true; boolean isWellFormed = true; String results; URI baseUri; SchemaIntf schema; String schemaPath; public String tstMessage; Vector parseErrors; public ExtSchemaValidator() { this.init(); } public void validate(String var1, String var2) { URI var3 = new URI(var1); if (!var3.exists()) { this.isSchemaValid = false; this.results = "File does not exist."; } else { this.validate(var3, var3, var2); } } public void validate(URI var1, URI var2, String var3, String var4) { this.schemaPath = var4; this.validate(var1, var2, var3); } public void validate(URI var1, URI var2, String var3) { try { if (var3 == null) { var3 = SchemaUtilities.getFlavor(var1, true); } this.schema = new Schema(var2, var3); this.schema.setSchemaPath(this.schemaPath); this.schema.setPrintValidatedBy(true); this.results = ""; try { this.schema.setShowErrors(true); this.schema.parse(var1, var2, this.schema.getCount(), new Boolean(false)); this.schema.doSecondPassValidation(var1); } catch (Throwable var9) { this.isSchemaValid = false; this.results = String.valueOf(String.valueOf(this.results).concat(String.valueOf(var9.getMessage()))).concat(String.valueOf("\r\n")); return; } if (this.schema != null) { this.checkAll(); this.parseErrors = this.schema.getParseErrors(); int var4 = this.countDeclErrors(); int var5 = this.schema.getCount(); if (this.parseErrors.isEmpty() && var4 == 0) { this.isSchemaValid = true; this.schema.setPrintValidatedBy(true); this.schema.setShowErrors(false); StringWriter var11 = new StringWriter(); this.schema.write(var11); this.results = String.valueOf(this.results).concat(String.valueOf(var11.toString())); } else { this.isSchemaValid = false; this.schema.setPrintValidatedBy(false); this.schema.setShowErrors(true); StringWriter var6 = new StringWriter(); try { this.schema.write(var6); } catch (Exception var8) { } this.results = String.valueOf(this.results).concat(String.valueOf(var6.toString())); } } else { this.isSchemaValid = false; this.isWellFormed = false; this.results = String.valueOf(this.results).concat(String.valueOf("Schema is not well-formed.")); } } catch (Exception var10) { this.isSchemaValid = false; this.isWellFormed = false; this.results = String.valueOf(String.valueOf(String.valueOf(String.valueOf(this.results).concat(String.valueOf("Schema is not well-formed."))).concat(String.valueOf(" "))).concat(String.valueOf(((Throwable)var10).getMessage()))).concat(String.valueOf("\r\n")); } } public String getResults() { return this.results; } public boolean isValid() { return this.isSchemaValid; } public boolean isWellFormed() { return this.isWellFormed; } private int countDeclErrors() { int var1 = 0; Enumeration var2 = this.schema.getDeclarations(); while(var2.hasMoreElements()) { BaseDeclaration var3 = (BaseDeclaration)var2.nextElement(); if (var3.hasErrors()) { ++var1; } } return var1; } public Vector getDeclErrors() { Vector var1 = new Vector(); Enumeration var2 = this.schema.getDeclarations(); while(var2.hasMoreElements()) { BaseDeclaration var3 = (BaseDeclaration)var2.nextElement(); if (var3.hasErrors()) { Enumeration var4 = var3.getErrors().elements(); while(var4.hasMoreElements()) { var1.addElement(var4.nextElement()); } } } return var1; } public Vector getParseErrors() { return this.parseErrors; } public Vector getAllErrors() { Vector var1 = new Vector(); if (this.parseErrors != null) { Enumeration var2 = this.parseErrors.elements(); while(var2.hasMoreElements()) { var1.addElement(var2.nextElement()); } } if (this.getDeclErrors() != null) { Enumeration var3 = this.getDeclErrors().elements(); while(var3.hasMoreElements()) { var1.addElement(var3.nextElement()); } } return var1; } private void checkAll() { Enumeration var1 = this.schema.getDeclarations(); while(var1.hasMoreElements()) { BaseDeclaration var2 = (BaseDeclaration)var1.nextElement(); boolean var3 = var2.hasErrors(); this.schema.checkForErrors(var2); } this.schema.checkForErrors((BaseDeclaration)null); } private void init() { this.XMLResources = ResourceBundle.getBundle("com.extensibility.xml.rsc.XMLResources"); this.ParserErrorBundle = ResourceBundle.getBundle("com.extensibility.xml.rsc.ParserExceptions"); ParserException.setMessageBundle(this.ParserErrorBundle); this.dataTypeDisplayNames = ResourceBundle.getBundle("com.extensibility.xml.rsc.DataTypes"); BaseFlavor.setDisplayNameBundle(this.dataTypeDisplayNames); BaseFlavor.loadDisplayNames(); BaseDeclaration.setResources(this.XMLResources); BaseExemplar.setResources(this.XMLResources); SchemaWriter.setResources(this.XMLResources); this.schemaPath = ""; } public void setSchemaPath(String var1) { this.schemaPath = var1; } }